%%% This matlab code produces Figure 1  

clear;clc;close all;

%%%%%%%%%%%%%%%%%%%  Figure 1

%%-- (A) GDP

GDP=xlsread('Macro_data','GDP','B7:F62');
figure(1)
plot(GDP(:,1),'LineWidth',2);hold on
plot(GDP(:,2),'--','LineWidth',2);hold on
plot(GDP(:,3),':','LineWidth',2);hold on
plot(GDP(:,4),'-.','LineWidth',2);hold on
plot(GDP(:,5),'+','LineWidth',2);hold on
line([33,33],[min(min(GDP)), max(max(GDP))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(GDP)), max(max(GDP))],'color','black','LineWidth',2);hold on
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
legend('Germany','Portugal','Italy','Greece','Spain','location','northwest')
grid on
axis tight
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'Real_GDP', 'pdf')

%%-- (B) VIX index, GIPS spread, and German bund yield

VIX=xlsread('Macro_data','Uncertainty, Bond and Stock','B7:B62');
Spread=xlsread('Macro_data','Uncertainty, Bond and Stock','H7:H62');
Lbond=xlsread('Macro_data','Uncertainty, Bond and Stock','C7:C62');
figure(2)
yyaxis left
plot(VIX,'LineWidth',2);
ylabel('VIX Index','interpret','latex')
yyaxis right
plot(Spread,'--','Color',[0.2 0.8 0.5],'LineWidth',2);hold on
plot(Lbond,':','Color',[1 0.2 .2],'LineWidth',2)
line([33,33],[min(min(Spread)), max(max(Spread))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(Spread)), max(max(Spread))],'color','black','LineWidth',2);hold on
grid on
axis tight
ylabel('GIPS Spread and German Bund Yield (\%)','interpret','latex')
legend('VIX (Left)','GIPS Spread (Right)','German Bund Yield (Right)','location','northwest')
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'Uncertainty', 'pdf')


%%-- (C) Credit by borrower (% of total)
All_To_Households_S=100*xlsread('Macro_data','Bank Lending (Quarterly)','Q11:Q66');
All_To_Enterprise_S=100*xlsread('Macro_data','Bank Lending (Quarterly)','R11:R66');
All_To_Foreign_S=100*xlsread('Macro_data','Bank Lending (Quarterly)','S11:S66');
figure(3)
yyaxis left
plot(All_To_Households_S,'Color',[0 0.5 .8],'LineWidth',2); hold on
plot(All_To_Enterprise_S,'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
yyaxis right
plot(All_To_Foreign_S,':','Color',[1 0.2 .2],'LineWidth',2);
line([33,33],[min(min(All_To_Foreign_S)), max(max(All_To_Foreign_S))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(All_To_Foreign_S)), max(max(All_To_Foreign_S))],'color','black','LineWidth',2);hold on
legend('To Households (left)','To Enterprise (left)','To Foreigners (right)','location','northwest')
grid on
axis tight
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'AllLending_Sectors_Shares', 'pdf')

%%-- (D) Total domestic credit by type of bank (% GDP)
AllLending_To_Domestic=100*xlsread('Macro_data','Bank Lending (Quarterly)','I11:I66');
DoLending_To_Domestic=100*xlsread('Macro_data','Bank Lending (Quarterly)','K11:K66');
ForeignLending_To_Domestic=100*xlsread('Macro_data','Bank Lending (Quarterly)','J11:J66');
figure(4)
yyaxis left
plot(AllLending_To_Domestic,'Color',[0 0.5 .8],'LineWidth',2); hold on
plot(DoLending_To_Domestic,'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
yyaxis right
plot(ForeignLending_To_Domestic,':','Color',[1 0.2 .2],'LineWidth',2);
line([33,33],[min(min(ForeignLending_To_Domestic)), max(max(ForeignLending_To_Domestic))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(ForeignLending_To_Domestic)), max(max(ForeignLending_To_Domestic))],'color','black','LineWidth',2);hold on
legend('All Banks (left)','German Banks (left)','Foreign Banks (right)','location','northwest')
grid on
axis tight
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'DomesticLending_Banks', 'pdf')


%%-- (E) Residential real estate (indexes, 2009=100)
Residential_HP=xlsread('Macro_data','Housing Market','F5:F18');
Residential_Rent=xlsread('Macro_data','Housing Market','H5:H18');
Residential_HP=[nan(3,1);Residential_HP];
Residential_Rent=[nan(3,1);Residential_Rent];

Commerical_HP=xlsread('Macro_data','Housing Market','G5:G18');
Commerical_Rent=xlsread('Macro_data','Housing Market','I5:I18');

figure(5)
plot([1:14],100*Residential_HP./Residential_Rent,':','LineWidth',2); hold on
plot([1:14],Residential_HP,'Color',[0 0.5 .8],'LineWidth',2); hold on
plot([1:14],Residential_Rent,'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
line([9,9],[min(Commerical_HP), max(Commerical_HP)],'color','black','LineWidth',2);hold on
line([12,12],[min(Commerical_HP), max(Commerical_HP)],'color','black','LineWidth',2);hold on
ylim([min(Commerical_HP) max(Commerical_HP)])
xlim([1 14])
legend('Price/Rent Ratio','Real Estate Price','Rent','location','northwest')
grid on
xticks([1,5,9,12,14])
xticklabels({'2001','2005','2009','2012','2014'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'ResidentialHP', 'pdf')


%%-- (F) Commercial Real Estate (Indexes, 2009=100)
figure(6)
plot(100*Commerical_HP./Commerical_Rent,':','LineWidth',2); hold on
plot([1:14],Commerical_HP,'Color',[0 0.5 .8],'LineWidth',2); hold on
plot(Commerical_Rent,'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
line([9,9],[min(min(Commerical_HP)), max(max(Commerical_HP))],'color','black','LineWidth',2);hold on
line([12,12],[min(min(Commerical_HP)), max(max(Commerical_HP))],'color','black','LineWidth',2);hold on
ylim([min(Commerical_HP) max(Commerical_HP)])
legend('Price/Rent Ratio','Real Estate Price','Rent','location','northwest')
axis tight
grid on
xticks([1,5,9,12,14])
xticklabels({'2001','2005','2009','2012','2014'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'CommercialHP', 'pdf')




%%%%%%%%%%%%%%%%%%%  Figure 3

%%-- (A) Current account balances (% of GDP)
CA=100*xlsread('Macro_data','CA','K7:M62');
figure (7)
plot(CA(:,1),'Color',[0 0.5 .8],'LineWidth',2); hold on
plot(CA(:,2),'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
plot(CA(:,3),':','Color',[1 0.2 .2],'LineWidth',2);
line([33,33],[min(min(CA)), max(max(CA))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(CA)), max(max(CA))],'color','black','LineWidth',2);hold on
legend('Total','Euro Area','Outside Euro Area','location','northwest')
grid on
axis tight
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'CA', 'pdf')

%%-- (B) Net bank inflows (% of GDP)
BI=xlsread('Macro_data','Bank Inflows','D6:E61');

figure (8)
plot(BI(:,1),'--','Color',[0.2 0.8 0.5],'LineWidth',2); hold on
plot(BI(:,2),':','Color',[1 0.2 .2],'LineWidth',2);
line([33,33],[min(min(BI)), max(max(BI))],'color','black','LineWidth',2);hold on
line([47,47],[min(min(BI)), max(max(BI))],'color','black','LineWidth',2);hold on
legend('Euro Area','Outside Euro Area','location','northwest')
grid on
axis tight
xticks([1,17,33,47,56])
xticklabels({'2001Q1','2005Q1','2009Q1','2012Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 11)
saveas(gcf, 'BI', 'pdf')




%%%%%%%%%%%%%%%%%%%  Figure 4
PIGS_spread=xlsread('Macro_data','PIGS spread','B10:B65');
figure(9)
yyaxis left 
plot(BI(25:end,1),'--','LineWidth',2); hold on
ylabel('Net Bank Inflows (\% of GDP)','interpret','latex')
yyaxis right
plot(PIGS_spread(25:end),'LineWidth',2); hold on
line([9,9],[min(PIGS_spread), max(PIGS_spread)],'color','black','LineWidth',2);hold on
line([13,13],[min(PIGS_spread), max(PIGS_spread)],'color','black','LineWidth',2);hold on
line([17,17],[min(PIGS_spread), max(PIGS_spread)],'color','black','LineWidth',2);hold on
line([23,23],[min(PIGS_spread), max(PIGS_spread)],'color','black','LineWidth',2);hold on
line([27,27],[min(PIGS_spread), max(PIGS_spread)],'color','black','LineWidth',2);hold on
ylabel('Spreads (\%)','interpret','latex')
grid on
axis tight
legend('Net Bank Inflows (left)','Spreads (right)','location','northwest')
xticks([1,9,13,17,23,27,32])
xticklabels({'2007Q1','2009Q1','2010Q1','2011Q1','2012Q3','2013Q3','2014Q4'})
set(gcf, 'PaperPosition', [0 0 5 5]); %Position the plot further to the left and down. Extend the plot to fill entire paper.
set(gcf, 'PaperSize', [5 5]); %Keep the same paper size
set(gca,'FontSize', 8)
saveas(gcf, 'Inflows_Spread', 'pdf')
